package com.kingdee.pda.ui.set_config;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.example.basecommon.utils.PreferencesUtils;
import com.kingdee.pda.R;
import com.kingdee.pda.entity.Warehouse;
import com.kingdee.pda.ui.activity.BaseTitleActivity;
import com.kingdee.pda.util.ConstantPreference;
import com.kyleduo.switchbutton.SwitchButton;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 条码截取配置
 * * Created by dlj
 * DATE 2022/4/17
 * TIME 15:20
 */
public class OutWarehouseConfigureActivity extends BaseTitleActivity {
    @BindView(R.id.sb_use_listener)
    SwitchButton sb_use_listener;
    @BindView(R.id.tv_skuRule)
    TextView tv_skuRule;
    @BindView(R.id.tv_setSkuRule)
    TextView tv_setSkuRule;
    @BindView(R.id.tv_snRule)
    TextView tv_snRule;
    @BindView(R.id.tv_setSnRule)
    TextView tv_setSnRule;

    public static void actionStartForResult(Activity context) {
        Intent intent = new Intent(context, OutWarehouseConfigureActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onActivityCreate(Bundle savedInstanceState) {
        super.onActivityCreate(savedInstanceState);
        setContentView(R.layout.activity_out_configure);
    }

    @Override
    protected void initView() {
        super.initView();
        setTitle("出库管理参数配置");

        sb_use_listener.setOnCheckedChangeListener((buttonView, isChecked) ->
                PreferencesUtils.putBoolean(OutWarehouseConfigureActivity.this, ConstantPreference.QRCODE_IS_OPEN, isChecked));

        boolean isOpen = PreferencesUtils.getBoolean(this, ConstantPreference.QRCODE_IS_OPEN);
        sb_use_listener.setChecked(isOpen);

    }

    @OnClick({R.id.tv_setSkuRule, R.id.tv_setSnRule})
    public void onViewClicked(View view) {
        Intent intent = new Intent(this, OutWarehouseConDetailActivity.class);
        switch (view.getId()) {
            case R.id.tv_setSkuRule:
                intent.putExtra("type", "sku");
                startActivity(intent);
                break;
            case R.id.tv_setSnRule:
                intent.putExtra("type", "sn");
                startActivity(intent);
                break;
        }
    }

    @Override
    protected void initData() {
        super.initData();
    }

    @Override
    public void changeWarehouse(Warehouse warehouse) {

    }

    @Override
    protected void onResume() {
        super.onResume();

        String skuRule = "";
        int skuBeforeX = PreferencesUtils.getInt(this, ConstantPreference.QR_SKU_BEFOREX);
        int skuAfterX = PreferencesUtils.getInt(this, ConstantPreference.QR_SKU_AFTERX);

        try {
            switch (PreferencesUtils.getInt(this, ConstantPreference.QR_SKU_RADIOBUTTONID)) {
                case 0:
                    skuRule = skuBeforeX + "-" + skuAfterX;
                    break;
                case 1:
                    skuRule = "截取前" + skuBeforeX + "位";
                    break;
                case 2:
                    skuRule = "截取后" + skuAfterX + "位";
                    break;
                case 3:
                    skuRule = "去掉前" + skuBeforeX + "位";
                    break;
                case 4:
                    skuRule = "去掉后" + skuAfterX + "位";
                    break;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        tv_skuRule.setText(skuRule);


        String snRule = "";
        int snBeforeX = PreferencesUtils.getInt(this, ConstantPreference.QR_SN_BEFOREX);
        int snAfterX = PreferencesUtils.getInt(this, ConstantPreference.QR_SN_AFTERX);

        try {
            switch (PreferencesUtils.getInt(this, ConstantPreference.QR_SN_RADIOBUTTONID)) {
                case 0:
                    snRule = snBeforeX + "-" + snAfterX;
                    break;
                case 1:
                    snRule = "截取前" + snBeforeX + "位";
                    break;
                case 2:
                    snRule = "截取后" + snAfterX + "位";
                    break;
                case 3:
                    snRule = "去掉前" + snBeforeX + "位";
                    break;
                case 4:
                    snRule = "去掉后" + snAfterX + "位";
                    break;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        tv_snRule.setText(snRule);
    }
}
